namespace Digitalmes.Domain.Entities.Mes.Calendars;

/// <summary>
/// 计划班次
/// </summary>
[SugarTable("cal_shift")]
public sealed class CalShift : AuditedEntity
{
    /// <summary>
    /// 计划 ID
    /// </summary>
    public long PlanId { get; set; }

    /// <summary>
    /// 排班计划
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(PlanId))]
    public CalPlan? CalPlan { get; set; }

    /// <summary>
    /// 班次名称，如 白班，夜班
    /// </summary>
    [NotNull]
    public string? Name { get; set; }

    /// <summary>
    /// 开始时间，如 08:00
    /// </summary>
    [NotNull]
    public string? StartTime { get; set; }

    /// <summary>
    /// 结束时间（可跨天），如 17:30
    /// </summary>
    [NotNull]
    public string? EndTime { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string? Remark { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 排班成员集合
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(CalMember.MemberId))]
    public List<CalMember>? Members { get; set; }

    /// <summary>
    /// 指定时间是否在当前班次内。
    /// </summary>
    /// <param name="time">时间</param>
    /// <returns></returns>
    public bool IsIn(TimeOnly time)
    {
        var start = TimeOnly.Parse(StartTime);
        var end = TimeOnly.Parse(EndTime);
        return time.IsBetween(start, end);
    }
}
